<template>
  <view class="container">
    <!-- <navbar bg-color="#E72A2A" title="课程" color="#ffffff">
      <view class="left-icon" slot="leftIcon" style="position: absolute">
        <view class="logo"> LOGO </view>
      </view>
    </navbar>
    <view class="header">
      <headerSearch
        class="search-box"
        bgColor="#ffffff"
        @searchClick.stop="searchClick"
      >
        <view class="left" slot="left" @click.stop="citySelect">
          <text>郑州市</text>
          <image :src="$img_path('/course/select.png')" mode="widthFix"></image>
        </view>
      </headerSearch>
      <view class="msg">
        <image :src="$img_path('/course/index/1.png')" mode="widthFix"></image>
      </view>
    </view> -->

    <view class="content">
      <!-- <view class="top">
        <view class="t-text"> 您需要什么服务? </view>
        <view class="service">
          <view
            class="item"
            @click="gotoPage('/pages/index/index')"
          >
            <image
              :src="$img_path('/course/index/2.png')"
              mode="widthFix"
            ></image>
          </view>
          <view class="item" @click="toModel('/pagesMall/index/index', 3)">
            <image
              :src="$img_path('/course/index/3.png')"
              mode="widthFix"
            ></image>
          </view>
          <view class="item item-M-style">
            <image
              :src="$img_path('/course/index/4.png')"
              mode="widthFix"
            ></image>
          </view>
        </view>
      </view> -->

      <view class="bg-box box-1" v-if="nav_8.length > 0">
        <view class="bg-con-box">
          <view class="item" v-for="(item, i) in nav_8" :key="item.id" @click="toList(item)">
            <image :src="$img_base_url(item.thumb_image)" mode="aspectFill"></image>
            <text>{{ item.name || "" }}</text>
          </view>
        </view>
      </view>
      <view class="bg-box box-1" v-if="nav_10.length > 0">
        <view class="bg-con-box" style="width: calc(100% + 40rpx)">
          <view
            class="item"
            v-for="(item, i) in nav_10"
            :key="item.id"
            style="width: calc(20% - 40rpx); margin-right: 40rpx"
          >
            <image style="width: 80rpx" :src="$img_base_url(item.thumb_image)" mode="aspectFill"></image>
            <text style="font-size: 26rpx">{{ item.name || "" }}</text>
          </view>
        </view>
      </view>
      <view class="Notice">
        <image :src="$img_path('/course/index/16.png')" mode="widthFix"></image>
        <view class="text"> 服务电话：12345678910 </view>
      </view>

      <!-- 首页广告一 -->
      <view class="swiper_1 swiper-box" v-if="Ads[0] && Ads[0].ads.length > 0">
        <swiper :autoplay="true" :interval="3000" :duration="1000">
          <swiper-item v-for="(item, i) in Ads[0].ads" :key="item.id" @click="toList(item)">
            <view class="swiper-item">
              <image :src="$img_base_url(item.thumb_image)" mode="aspectFill"></image>
            </view>
          </swiper-item>
        </swiper>
      </view>

      <view
        class="bg-box box-3"
        v-if="(Ads[1] && Ads[1].ads.length > 0) || (Ads[2] && Ads[2].ads.length > 0)"
      >
        <!-- <image class="bg-img" :src="$img_path('/course/index/bg2.png')" mode="widthFix"></image> -->
        <!-- <view class="title">
					<view class="left">
						<image :src="$img_path('/course/index/15.png')" mode="widthFix"></image>
						<text>优惠券</text>
					</view>
					<view class="right">
						<text>更多</text>
						<image :src="$img_path('/course/index/icon_r.png')" mode="widthFix"></image>
					</view>
				</view>
				
				<view class="coupon">
					<view class="c-box">
						<view class="item" v-for="item in 4">
							<image :src="$img_path('/course/index/c.png')" mode="widthFix"></image>
						</view>
					</view>
				</view> -->
        <view class="t-img">
          <!-- 首页广告2 -->
          <view class="i" v-if="Ads[1] && Ads[1].ads.length > 0">
            <swiper style="width: 100%; height: 100%" :autoplay="true" :interval="3000" :duration="1000">
              <swiper-item style="width: 100%; height: 100%" v-for="(item, i) in Ads[1].ads" :key="item.id">
                <view class="swiper-item" style="width: 100%; height: 100%" @click="toList(item)">
                  <image
                    style="width: 100%; height: 100%"
                    :src="$img_base_url(item.thumb_image)"
                    mode="aspectFill"
                  ></image>
                </view>
              </swiper-item>
            </swiper>
          </view>
          <!-- 首页广告3 -->
          <view class="i" v-if="Ads[2] && Ads[2].ads.length > 0">
            <swiper style="width: 100%; height: 100%" :autoplay="true" :interval="3000" :duration="1000">
              <swiper-item style="width: 100%; height: 100%" v-for="(item, i) in Ads[2].ads" :key="item.id">
                <view class="swiper-item" style="width: 100%; height: 100%" @click="toList(item)">
                  <image
                    style="width: 100%; height: 100%"
                    :src="$img_base_url(item.thumb_image)"
                    mode="aspectFill"
                  ></image>
                </view>
              </swiper-item>
            </swiper>
          </view>
        </view>
      </view>

      <!-- 首页广告4 -->
      <view class="swiper_1 swiper-box" v-if="Ads[3] && Ads[3].ads.length > 0">
        <swiper :autoplay="true" :interval="3000" :duration="1000">
          <swiper-item>
            <view class="swiper-item" v-for="(item, i) in Ads[3].ads" :key="item.id" @click="toList(item)">
              <image :src="$img_base_url(item.thumb_image)" mode="aspectFill"></image>
            </view>
          </swiper-item>
        </swiper>
      </view>
      <view class="list-box bg-box">
        <view class="item" v-for="(item, i) in moduleInfo[0].course" :key="item.id">
          <goodsBox
            :styleType="2"
            :goodsDetail="item"
            :imageStyle="{ width: '324rpx', height: '232rpx' }"
            @goodsClick="goodsClick(item)"
          >
            <text slot="center">{{ item.collection_count || "" }}人订阅</text>
          </goodsBox>
        </view>
      </view>
      <!-- 首页广告5 -->
      <view class="swiper_1 swiper-box" v-if="Ads[4] && Ads[4].ads.length > 0">
        <swiper :autoplay="true" :interval="3000" :duration="1000">
          <swiper-item>
            <view class="swiper-item" v-for="(item, i) in Ads[4].ads" @click="toList(item)" :key="item.id">
              <image :src="$img_base_url(item.thumb_image)" mode="aspectFill"></image>
            </view>
          </swiper-item>
        </swiper>
      </view>
      <view class="list-box bg-box">
        <view class="item" v-for="(item, i) in moduleInfo[1].course" :key="item.id">
          <goodsBox
            :styleType="2"
            :goodsDetail="item"
            :imageStyle="{ width: '324rpx', height: '232rpx' }"
            @goodsClick="goodsClick(item)"
          >
            <text slot="center">{{ item.collection_count || "" }}人订阅</text>
          </goodsBox>
        </view>
      </view>
      <!-- 首页广告6 -->
      <view class="swiper_1 swiper-box" v-if="Ads[5] && Ads[5].ads.length > 0">
        <swiper :autoplay="true" :interval="3000" :duration="1000">
          <swiper-item>
            <view class="swiper-item" v-for="(item, i) in Ads[5].ads" :key="item.id">
              <image :src="$img_base_url(item.thumb_image)" mode="aspectFill"></image>
            </view>
          </swiper-item>
        </swiper>
      </view>
      <view class="list-box row-list bg-box">
        <view class="title">
          {{ moduleInfo[2].name || "" }}
        </view>
        <view class="item" v-for="(item, i) in moduleInfo[2].course" :key="item.id">
          <goodsBox :styleType="1" :goodsDetail="item" @goodsClick="goodsClick(item)">
            <text slot="center">{{ item.collection_count || "" }}人订阅</text>
          </goodsBox>
        </view>
      </view>
      <!-- 首页广告7 -->
      <view class="swiper_1 swiper-box" v-if="Ads[6] && Ads[6].ads.length > 0">
        <swiper :autoplay="true" :interval="3000" :duration="1000">
          <swiper-item>
            <view class="swiper-item" v-for="(item, i) in Ads[6].ads" :key="item.id">
              <image :src="$img_base_url(item.thumb_image)" mode="aspectFill"></image>
            </view>
          </swiper-item>
        </swiper>
      </view>
      <view class="list-box row-list bg-box">
        <view class="title">
          {{ moduleInfo[3].name || "" }}
        </view>
        <view class="item" v-for="(item, i) in moduleInfo[3].course" :key="i">
          <goodsBox :styleType="1" :goodsDetail="item" @goodsClick="goodsClick(item)">
            <text slot="center">{{ item.collection_count || "" }}人订阅</text>
          </goodsBox>
        </view>
      </view>
    </view>

    <view class="bottom-img-1" v-if="Ads[7] && Ads[7].ads.length > 0">
      <!-- <image style="margin: 32rpx auto 0;" :src="$img_path('/mall/2.png')" mode="aspectFill"></image> -->
      <swiper
        style="width: 622rpx; height: 126rpx; margin: 32rpx auto 0"
        :autoplay="true"
        :interval="3000"
        :duration="1000"
      >
        <swiper-item style="width: 100%; height: 100%" v-for="(item, i) in Ads[7].ads" :key="item.id">
          <view class="swiper-item" style="width: 100%; height: 100%">
            <image
              style="width: 100%; height: 100%"
              :src="$img_base_url(item.thumb_image)"
              mode="aspectFill"
            ></image>
          </view>
        </swiper-item>
      </swiper>
    </view>
    <!-- <view class="bottom-img-2" style="padding-bottom: 20rpx">
      <image
        style="width: 228rpx; height: 82rpx; margin: 90rpx auto 0"
        :src="$img_path('/mall/2.png')"
        mode="aspectFill"
      ></image>
    </view> -->
    <view class="bottom-img">
      <image :src="$img_path('/course/index/bg.png')" mode="widthFix"></image>
      <image :src="$img_path('/course/index/bg.png')" mode="widthFix"></image>
    </view>

    <view class="scroll-top" v-if="s_top" @click="toTop">
      <image :src="$img_path('/course/top.png')" mode="widthFix"></image>
    </view>
    <Tarbar index="1" page="2"></Tarbar>
  </view>
</template>

<script>
import { getNav, getAds, indexModule, coupon_lists } from "@/utils/api/public.js";
import goodsBox from "@/components/service-box/goods-box.vue";
import headerSearch from "@/components/header-search/header-search.vue";
export default {
  name: "courseIndex",
  components: {
    headerSearch,
    goodsBox,
  },
  props: {
    // 上拉刷新
    scrollTop: {
      type: Number,
      default: 0,
    },
  },
  watch: {
    scrollTop(val) {
      this.getNavApi();
      this.getAdsApi();
      this.getindexModule();
    },
  },
  data() {
    return {
      s_top: false,
      nav_8: [],
      nav_10: [],
      moduleInfo: null,
      Ads: [],
    };
  },
  onLoad() {},
  onShow() {
    this.city = JSON.parse(uni.getStorageSync("select_city"));
  },
  mounted() {
    console.log(11111199);
    this.getNavApi();
    this.getAdsApi();
    this.getindexModule();
  },
  methods: {
    // 获取导航
    async getNavApi() {
      let nav_8 = await getNav({ group: 1, type: 3 });
      this.nav_8 = nav_8.data;
      let nav_10 = await getNav({ group: 2, type: 3 });
      this.nav_10 = nav_10.data;
    },

    // 获取广告
    async getAdsApi() {
      let adList = await getAds({ type: 3 });
      console.log(adList, "-");
      this.Ads = adList.data;
    },

    // 获取首页模块配置
    async getindexModule() {
      let module = await indexModule({ type: 3 });
      // console.log(module,'-')
      this.moduleInfo = module.data;
    },

    // 获取优惠券
    get_coupon_lists() {},

    toModel(url, i) {
      uni.setStorageSync("tarbarModule", i);
      uni.reLaunch({
        url: url,
      });
    },

    gotoPage(url, i) {
      uni.setStorageSync("tarbarModule", i);
      uni.navigateTo({
        url,
      });
    },

    goodsClick(data) {
      uni.navigateTo({
        url: `/pagesCourse/webview/webview?url=pagesCourse/classify/detail&id=${data.id}`,
      });
    },

    toList(item) {
      // location.href = item.url
      if (item.url_type == 1) {
        // uni.navigateTo({
        // 	url:`/pagesMall/webView/webView?url=${item.url}`
        // })
        // location.href = item.url
      } else {
        uni.navigateTo({
          url: item.url,
        });
      }
    },
    toTop() {
      uni.pageScrollTo({
        scrollTop: 0,
        duration: 100,
      });
    },

    searchClick() {
      uni.navigateTo({
        url: "/pagesCourse/search/search",
      });
    },
    citySelect() {
      uni.navigateTo({
        url: "/pagesMine/city_select/city_select",
      });
    },
  },
  onPageScroll(event) {
    if (event.scrollTop > 100) {
      this.s_top = true;
    } else {
      this.s_top = false;
    }
  },
};
</script>

<style lang="scss" scoped>
.container {
  .left-icon {
    left: 22rpx;
    width: 142rpx;
    height: 68rpx;
    background: #f8f8f8;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .header {
    display: flex;
    align-items: center;
    padding: 20rpx 22rpx 24rpx;
    background-color: #e72a2a;
    .search-box {
      background-color: #ffffff;
      height: 72rpx;
      border-radius: 37rpx;
      padding: 0 28rpx;
      box-sizing: border-box;
    }
    .left {
      display: flex;
      align-items: center;
      text {
        font-weight: 400;
        font-size: 26rpx;
        color: #333333;
        line-height: 36rpx;
      }
      image {
        width: 16rpx;
        height: 16rpx;
        margin-left: 8rpx;
      }
      border-right: 1rpx solid #cccccc;
      padding-right: 24rpx;
      box-sizing: border-box;
    }

    .msg {
      padding-left: 24rpx;
      height: 40rpx;
      image {
        width: 40rpx;
        height: 40rpx;
      }
    }
  }
  .content {
    // padding: 0 22rpx;
    box-sizing: border-box;
    .top {
      padding-top: 20rpx;
      .t-text {
        font-weight: 800;
        font-size: 40rpx;
        color: #333333;
        line-height: 56rpx;
        text-align: center;
      }
      .service {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-top: 28rpx;
        .item {
          flex: 1;
          image {
            width: 100%;
            height: 220rpx;
          }
        }
        .item + .item {
          margin-left: 20rpx;
        }
        .item-M-style {
          // width: calc(43.3% - 13.4rpx);
          flex: 1.2;
        }
      }
    }

    .bg-box {
      background-color: #ffffff;
      border-radius: 20rpx;
    }
    .box-1 {
      padding: 18rpx 8px;
      box-sizing: border-box;
      margin-top: 20rpx;
      overflow: hidden;
      .bg-con-box {
        // width: calc(100% + 67rpx);
        // display: flex;
        // flex-wrap: wrap;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 20rpx;
        .item {
          // width: calc(25% - 66rpx);
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          // margin-right: 66rpx;
          // margin-bottom: 20rpx;
          image {
            width: 96rpx;
            height: 96rpx;
          }
          text {
            font-weight: bold;
            font-size: 30rpx;
            color: #333333;
            line-height: 42rpx;
            // margin-top: -10rpx;
          }
        }
      }
    }

    .Notice {
      background-color: #ffffff;
      height: 64rpx;
      border-radius: 32rpx;
      display: flex;
      align-items: center;
      padding: 18rpx 28rpx;
      box-sizing: border-box;
      margin-top: 20rpx;
      image {
        width: 32rpx;
        height: 27rpx;
      }
      .text {
        font-weight: 400;
        font-size: 26rpx;
        color: #333333;
        line-height: 36rpx;
        margin-left: 16rpx;
      }
    }

    .swiper_1 {
      width: 100%;
      height: 272rpx;
      margin-top: 20rpx;
      swiper {
        width: 100%;
        height: 100%;
        swiper-item {
          width: 100%;
          height: 100%;
        }
        .swiper-item {
          width: 100%;
          border-radius: 20rpx;
          overflow: hidden;
          image {
            width: 100%;
            height: 272rpx;
          }
        }
      }
    }

    .box-3 {
      width: 100%;
      position: relative;
      padding: 22rpx 20rpx;
      box-sizing: border-box;
      margin-top: 20rpx;
      background: #ffffff;
      border-radius: 16rpx 16rpx 16rpx 16rpx;
      box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.04);
      overflow: hidden;
      .bg-img {
        width: calc(100% + 40rpx);
        position: absolute;
        top: -14rpx;
        left: -20rpx;
        z-index: 0;
      }
      .title {
        display: flex;
        align-items: center;
        position: relative;
        z-index: 1;
        justify-content: space-between;
        .left {
          display: flex;
          justify-content: flex-start;
          align-items: center;
          image {
            width: 48rpx;
            height: 48rpx;
          }
          text {
            display: block;
            font-weight: bold;
            font-size: 36rpx;
            color: #333333;
            line-height: 50rpx;
            margin-left: 2rpx;
          }
        }
        .right {
          display: flex;
          justify-content: flex-end;
          align-items: center;
          image {
            width: 24rpx;
            height: 24rpx;
            margin-top: 4rpx;
          }
          text {
            display: block;
            font-weight: 400;
            font-size: 30rpx;
            color: #333333;
            line-height: 42rpx;
          }
        }
      }

      .coupon {
        width: 100%;
        overflow: hidden;
        margin-top: 18rpx;
        position: relative;
        z-index: 1;
        .c-box {
          width: calc(100% + 18rpx);
          display: flex;
          align-items: center;
          .item {
            width: calc(25% - 18rpx);
            margin-right: 18rpx;
            image {
              width: 100%;
              height: 100%;
            }
          }
        }
      }

      .t-img {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-top: 20rpx;
        position: relative;
        z-index: 1;
        .i {
          width: calc(50% - 10rpx);
          height: 204rpx;
          border-radius: 20rpx;
          box-sizing: border-box;
          overflow: hidden;
          image {
            width: 100%;
            height: 100%;
          }
        }
      }
    }

    .list-box {
      margin-top: 20rpx;
      &.row-list {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        padding: 20rpx;
        box-sizing: border-box;
        .title {
          width: 100%;
          font-weight: bold;
          font-size: 36rpx;
          color: #333333;
          line-height: 50rpx;
          padding-bottom: 20rpx;
        }
        .item {
          width: calc(50% - 9rpx);
        }
      }
    }
  }
}

.scroll-top {
  position: fixed;
  bottom: 400rpx;
  right: 22rpx;
  z-index: 9;
  image {
    width: 80rpx;
    height: 80rpx;
  }
}

.bottom-img {
  margin-top: 40rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  image + image {
    width: 300rpx;
    margin-top: 40rpx;
  }
}
</style>
